/**
 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package pe.edu.aprolab.base.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.json.JSON;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import pe.edu.aprolab.base.model.Institucion;
import pe.edu.aprolab.base.model.InstitucionModel;
import pe.edu.aprolab.base.model.InstitucionSoap;

import java.io.Serializable;

import java.sql.Types;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * The base model implementation for the Institucion service. Represents a row in the &quot;BASE_Institucion&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link pe.edu.aprolab.base.model.InstitucionModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link InstitucionImpl}.
 * </p>
 *
 * @author Jorge Loayza Soloisolo
 * @see InstitucionImpl
 * @see pe.edu.aprolab.base.model.Institucion
 * @see pe.edu.aprolab.base.model.InstitucionModel
 * @generated
 */
@JSON(strict = true)
public class InstitucionModelImpl extends BaseModelImpl<Institucion>
	implements InstitucionModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a institucion model instance should use the {@link pe.edu.aprolab.base.model.Institucion} interface instead.
	 */
	public static final String TABLE_NAME = "BASE_Institucion";
	public static final Object[][] TABLE_COLUMNS = {
			{ "institucionId", Types.BIGINT },
			{ "companyId", Types.BIGINT },
			{ "createDate", Types.TIMESTAMP },
			{ "modifiedDate", Types.TIMESTAMP },
			{ "formacionId", Types.BIGINT },
			{ "RUC", Types.VARCHAR },
			{ "codigoModular", Types.VARCHAR }
		};
	public static final String TABLE_SQL_CREATE = "create table BASE_Institucion (institucionId LONG not null primary key,companyId LONG,createDate DATE null,modifiedDate DATE null,formacionId LONG,RUC VARCHAR(75) null,codigoModular VARCHAR(75) null)";
	public static final String TABLE_SQL_DROP = "drop table BASE_Institucion";
	public static final String ORDER_BY_JPQL = " ORDER BY institucion.RUC ASC";
	public static final String ORDER_BY_SQL = " ORDER BY BASE_Institucion.RUC ASC";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.pe.edu.aprolab.base.model.Institucion"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.pe.edu.aprolab.base.model.Institucion"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.column.bitmask.enabled.pe.edu.aprolab.base.model.Institucion"),
			true);
	public static long RUC_COLUMN_BITMASK = 1L;
	public static long CODIGOMODULAR_COLUMN_BITMASK = 2L;
	public static long COMPANYID_COLUMN_BITMASK = 4L;

	/**
	 * Converts the soap model instance into a normal model instance.
	 *
	 * @param soapModel the soap model instance to convert
	 * @return the normal model instance
	 */
	public static Institucion toModel(InstitucionSoap soapModel) {
		if (soapModel == null) {
			return null;
		}

		Institucion model = new InstitucionImpl();

		model.setInstitucionId(soapModel.getInstitucionId());
		model.setCompanyId(soapModel.getCompanyId());
		model.setCreateDate(soapModel.getCreateDate());
		model.setModifiedDate(soapModel.getModifiedDate());
		model.setFormacionId(soapModel.getFormacionId());
		model.setRUC(soapModel.getRUC());
		model.setCodigoModular(soapModel.getCodigoModular());

		return model;
	}

	/**
	 * Converts the soap model instances into normal model instances.
	 *
	 * @param soapModels the soap model instances to convert
	 * @return the normal model instances
	 */
	public static List<Institucion> toModels(InstitucionSoap[] soapModels) {
		if (soapModels == null) {
			return null;
		}

		List<Institucion> models = new ArrayList<Institucion>(soapModels.length);

		for (InstitucionSoap soapModel : soapModels) {
			models.add(toModel(soapModel));
		}

		return models;
	}

	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.pe.edu.aprolab.base.model.Institucion"));

	public InstitucionModelImpl() {
	}

	@Override
	public long getPrimaryKey() {
		return _institucionId;
	}

	@Override
	public void setPrimaryKey(long primaryKey) {
		setInstitucionId(primaryKey);
	}

	@Override
	public Serializable getPrimaryKeyObj() {
		return _institucionId;
	}

	@Override
	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	@Override
	public Class<?> getModelClass() {
		return Institucion.class;
	}

	@Override
	public String getModelClassName() {
		return Institucion.class.getName();
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("institucionId", getInstitucionId());
		attributes.put("companyId", getCompanyId());
		attributes.put("createDate", getCreateDate());
		attributes.put("modifiedDate", getModifiedDate());
		attributes.put("formacionId", getFormacionId());
		attributes.put("RUC", getRUC());
		attributes.put("codigoModular", getCodigoModular());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long institucionId = (Long)attributes.get("institucionId");

		if (institucionId != null) {
			setInstitucionId(institucionId);
		}

		Long companyId = (Long)attributes.get("companyId");

		if (companyId != null) {
			setCompanyId(companyId);
		}

		Date createDate = (Date)attributes.get("createDate");

		if (createDate != null) {
			setCreateDate(createDate);
		}

		Date modifiedDate = (Date)attributes.get("modifiedDate");

		if (modifiedDate != null) {
			setModifiedDate(modifiedDate);
		}

		Long formacionId = (Long)attributes.get("formacionId");

		if (formacionId != null) {
			setFormacionId(formacionId);
		}

		String RUC = (String)attributes.get("RUC");

		if (RUC != null) {
			setRUC(RUC);
		}

		String codigoModular = (String)attributes.get("codigoModular");

		if (codigoModular != null) {
			setCodigoModular(codigoModular);
		}
	}

	@JSON
	@Override
	public long getInstitucionId() {
		return _institucionId;
	}

	@Override
	public void setInstitucionId(long institucionId) {
		_institucionId = institucionId;
	}

	@JSON
	@Override
	public long getCompanyId() {
		return _companyId;
	}

	@Override
	public void setCompanyId(long companyId) {
		_columnBitmask |= COMPANYID_COLUMN_BITMASK;

		if (!_setOriginalCompanyId) {
			_setOriginalCompanyId = true;

			_originalCompanyId = _companyId;
		}

		_companyId = companyId;
	}

	public long getOriginalCompanyId() {
		return _originalCompanyId;
	}

	@JSON
	@Override
	public Date getCreateDate() {
		return _createDate;
	}

	@Override
	public void setCreateDate(Date createDate) {
		_createDate = createDate;
	}

	@JSON
	@Override
	public Date getModifiedDate() {
		return _modifiedDate;
	}

	@Override
	public void setModifiedDate(Date modifiedDate) {
		_modifiedDate = modifiedDate;
	}

	@JSON
	@Override
	public long getFormacionId() {
		return _formacionId;
	}

	@Override
	public void setFormacionId(long formacionId) {
		_formacionId = formacionId;
	}

	@JSON
	@Override
	public String getRUC() {
		if (_RUC == null) {
			return StringPool.BLANK;
		}
		else {
			return _RUC;
		}
	}

	@Override
	public void setRUC(String RUC) {
		_columnBitmask = -1L;

		if (_originalRUC == null) {
			_originalRUC = _RUC;
		}

		_RUC = RUC;
	}

	public String getOriginalRUC() {
		return GetterUtil.getString(_originalRUC);
	}

	@JSON
	@Override
	public String getCodigoModular() {
		if (_codigoModular == null) {
			return StringPool.BLANK;
		}
		else {
			return _codigoModular;
		}
	}

	@Override
	public void setCodigoModular(String codigoModular) {
		_columnBitmask |= CODIGOMODULAR_COLUMN_BITMASK;

		if (_originalCodigoModular == null) {
			_originalCodigoModular = _codigoModular;
		}

		_codigoModular = codigoModular;
	}

	public String getOriginalCodigoModular() {
		return GetterUtil.getString(_originalCodigoModular);
	}

	public long getColumnBitmask() {
		return _columnBitmask;
	}

	@Override
	public ExpandoBridge getExpandoBridge() {
		return ExpandoBridgeFactoryUtil.getExpandoBridge(getCompanyId(),
			Institucion.class.getName(), getPrimaryKey());
	}

	@Override
	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		ExpandoBridge expandoBridge = getExpandoBridge();

		expandoBridge.setAttributes(serviceContext);
	}

	@Override
	public Institucion toEscapedModel() {
		if (_escapedModel == null) {
			_escapedModel = (Institucion)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelInterfaces, new AutoEscapeBeanHandler(this));
		}

		return _escapedModel;
	}

	@Override
	public Object clone() {
		InstitucionImpl institucionImpl = new InstitucionImpl();

		institucionImpl.setInstitucionId(getInstitucionId());
		institucionImpl.setCompanyId(getCompanyId());
		institucionImpl.setCreateDate(getCreateDate());
		institucionImpl.setModifiedDate(getModifiedDate());
		institucionImpl.setFormacionId(getFormacionId());
		institucionImpl.setRUC(getRUC());
		institucionImpl.setCodigoModular(getCodigoModular());

		institucionImpl.resetOriginalValues();

		return institucionImpl;
	}

	@Override
	public int compareTo(Institucion institucion) {
		int value = 0;

		value = getRUC().compareTo(institucion.getRUC());

		if (value != 0) {
			return value;
		}

		return 0;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}

		if (!(obj instanceof Institucion)) {
			return false;
		}

		Institucion institucion = (Institucion)obj;

		long primaryKey = institucion.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public void resetOriginalValues() {
		InstitucionModelImpl institucionModelImpl = this;

		institucionModelImpl._originalCompanyId = institucionModelImpl._companyId;

		institucionModelImpl._setOriginalCompanyId = false;

		institucionModelImpl._originalRUC = institucionModelImpl._RUC;

		institucionModelImpl._originalCodigoModular = institucionModelImpl._codigoModular;

		institucionModelImpl._columnBitmask = 0;
	}

	@Override
	public CacheModel<Institucion> toCacheModel() {
		InstitucionCacheModel institucionCacheModel = new InstitucionCacheModel();

		institucionCacheModel.institucionId = getInstitucionId();

		institucionCacheModel.companyId = getCompanyId();

		Date createDate = getCreateDate();

		if (createDate != null) {
			institucionCacheModel.createDate = createDate.getTime();
		}
		else {
			institucionCacheModel.createDate = Long.MIN_VALUE;
		}

		Date modifiedDate = getModifiedDate();

		if (modifiedDate != null) {
			institucionCacheModel.modifiedDate = modifiedDate.getTime();
		}
		else {
			institucionCacheModel.modifiedDate = Long.MIN_VALUE;
		}

		institucionCacheModel.formacionId = getFormacionId();

		institucionCacheModel.RUC = getRUC();

		String RUC = institucionCacheModel.RUC;

		if ((RUC != null) && (RUC.length() == 0)) {
			institucionCacheModel.RUC = null;
		}

		institucionCacheModel.codigoModular = getCodigoModular();

		String codigoModular = institucionCacheModel.codigoModular;

		if ((codigoModular != null) && (codigoModular.length() == 0)) {
			institucionCacheModel.codigoModular = null;
		}

		return institucionCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(15);

		sb.append("{institucionId=");
		sb.append(getInstitucionId());
		sb.append(", companyId=");
		sb.append(getCompanyId());
		sb.append(", createDate=");
		sb.append(getCreateDate());
		sb.append(", modifiedDate=");
		sb.append(getModifiedDate());
		sb.append(", formacionId=");
		sb.append(getFormacionId());
		sb.append(", RUC=");
		sb.append(getRUC());
		sb.append(", codigoModular=");
		sb.append(getCodigoModular());
		sb.append("}");

		return sb.toString();
	}

	@Override
	public String toXmlString() {
		StringBundler sb = new StringBundler(25);

		sb.append("<model><model-name>");
		sb.append("pe.edu.aprolab.base.model.Institucion");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>institucionId</column-name><column-value><![CDATA[");
		sb.append(getInstitucionId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>companyId</column-name><column-value><![CDATA[");
		sb.append(getCompanyId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>createDate</column-name><column-value><![CDATA[");
		sb.append(getCreateDate());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>modifiedDate</column-name><column-value><![CDATA[");
		sb.append(getModifiedDate());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>formacionId</column-name><column-value><![CDATA[");
		sb.append(getFormacionId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>RUC</column-name><column-value><![CDATA[");
		sb.append(getRUC());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>codigoModular</column-name><column-value><![CDATA[");
		sb.append(getCodigoModular());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = Institucion.class.getClassLoader();
	private static Class<?>[] _escapedModelInterfaces = new Class[] {
			Institucion.class
		};
	private long _institucionId;
	private long _companyId;
	private long _originalCompanyId;
	private boolean _setOriginalCompanyId;
	private Date _createDate;
	private Date _modifiedDate;
	private long _formacionId;
	private String _RUC;
	private String _originalRUC;
	private String _codigoModular;
	private String _originalCodigoModular;
	private long _columnBitmask;
	private Institucion _escapedModel;
}